<?php
if(!isset($_SESSION)){
	session_start();
}
if(empty($_SESSION['logind'])){
	echo '<script>top.location.href="./login.php";</script>';
	exit();
}
if($_SERVER['REQUEST_METHOD'] == 'POST'){
	$constr = '<?php'.chr(10);
	$constr .= 'define('.'\'TITLE\''.', \''.$_POST['title'].'\');'.chr(10);
	$constr .= 'define('.'\'USERNAME\''.', \''.$_POST['username'].'\');'.chr(10);
	$constr .= 'define('.'\'PASSWORD\''.', \''.$_POST['pwd'].'\');'.chr(10).'?>';
	file_put_contents('./config.php', $constr);
	unset($_SESSION['logind']);
	header('Content-Type:text/html;charset=utf-8');
	echo '<script>alert("修改成功！");top.location.href="./login.php";</script>';
	exit();
}
include 'config.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>后台管理系统</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/select.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/select-ui.min.js"></script>
 
<script type="text/javascript">
$(document).ready(function(e) {
    $(".select1").uedSelect({
		width : 345			  
	});
	$(".select2").uedSelect({
		width : 167  
	});
	$(".select3").uedSelect({
		width : 100
	});
	
});

function checkForm(){
	var pwd = document.newsform.pwd.value;
	if(pwd==""){
		alert("请输入密码！");
		document.newsform.pwd.focus();
		return false;
	}else if(pwd.length < 6){
		alert("密码长度不小于6位！");
		document.newsform.pwd.focus();
		return false;
	}
}
</script>

</head>

<body>
    <form action="" method="post" name="newsform" onSubmit="return checkForm();">
    <div class="formbody">
		<div class="formtitle"><span>后台配置</span></div>
		<ul class="forminfo">
			<li><label>后台标题</label><input name="title" type="text" class="dfinput" maxlength="20" value="<?php echo TITLE;?>" /></li>
			<li><label>登录用户</label><input name="username" type="text" class="dfinput" maxlength="20" value="<?php echo USERNAME;?>" /></li>
			<li><label>登录密码</label><input name="pwd" type="password" class="dfinput" maxlength="20" value="<?php echo PASSWORD;?>" /></li>
			<li><label>&nbsp;</label><input name="" type="submit" class="btn" value="修 改"/></li>
		</ul>
		</div>
	</form>
</body>
</html>